package com.szlib.seeker.cron;

import java.text.ParseException;
import java.util.Locale;

import org.junit.jupiter.api.Test;

//import org.junit.Test;

import com.cronutils.descriptor.CronDescriptor;
import com.cronutils.model.Cron;
import com.cronutils.model.CronType;
import com.cronutils.model.definition.CronDefinition;
import com.cronutils.model.definition.CronDefinitionBuilder;
import com.cronutils.parser.CronParser;


public class CronExpressTests5 {
	
	@Test
	public void test() throws ParseException {
//		CronExpressionUtil
		String s="0 0 18 28–31 * ?";
		//0 23 * ? * 1-5 *
		CronDefinition cronDefinition =
			    CronDefinitionBuilder.defineCron()
			        .withSeconds().and()
			        .withMinutes().and()
			        .withHours().and()
			        .withDayOfMonth()
			            .supportsHash().supportsL().supportsW().and()
			        .withMonth().and()
			        .withDayOfWeek()
			            .withIntMapping(7, 0) //we support non-standard non-zero-based numbers!
			            .supportsHash().supportsL().supportsW().and()
			        .withYear().optional().and()
			        .instance();
		cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
		// Create a descriptor for a specific Locale
		CronDescriptor descriptor = CronDescriptor.instance(Locale.SIMPLIFIED_CHINESE);
		CronParser parser = new CronParser(cronDefinition);
		Cron quartzCron = parser.parse(s);
		// Parse some expression and ask descriptor for description
		String description = descriptor.describe(parser.parse("*/45 * * * * ?"));
		// Description will be: "every 45 seconds"
		System.out.println(description);
		description = descriptor.describe(quartzCron);
		System.out.println(description);
		// Description will be: "every hour at minute 23 every day between Monday and Friday"
		// which is the same description we get for the cron below:
		descriptor.describe(parser.parse("0 23 * ? * MON-FRI *"));
		System.out.println(description);
		descriptor.describe(parser.parse("1-2 ? 0/1 1,3,6,8,9,11,12,14,15 1/1 1/2"));
		System.out.println(description);
	}

}
